(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

plus(x, 0) → x
plus(0, y) → y
plus(s(x), y) → s(plus(x, y))
times(0, y) → 0
times(s(0), y) → y
times(s(x), y) → plus(y, times(x, y))
div(0, y) → 0
div(x, y) → quot(x, y, y)
quot(0, s(y), z) → 0
quot(s(x), s(y), z) → quot(x, y, z)
quot(x, 0, s(z)) → s(div(x, s(z)))
div(div(x, y), z) → div(x, times(y, z))

Rewrite Strategy: INNERMOST

(1) NestedDefinedSymbolProof (BOTH BOUNDS(ID, ID) transformation)

The following defined symbols can occur below the 1th argument of plus: plus, times

Hence, the left-hand sides of the following rules are not basic-reachable and can be removed:
div(div(x, y), z) → div(x, times(y, z))

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

plus(s(x), y) → s(plus(x, y))
times(s(x), y) → plus(y, times(x, y))
quot(x, 0, s(z)) → s(div(x, s(z)))
plus(x, 0) → x
plus(0, y) → y
div(0, y) → 0
div(x, y) → quot(x, y, y)
times(s(0), y) → y
quot(s(x), s(y), z) → quot(x, y, z)
times(0, y) → 0
quot(0, s(y), z) → 0

Rewrite Strategy: INNERMOST

(3) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(4) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

plus(s(x), y) → s(plus(x, y)) [1]
times(s(x), y) → plus(y, times(x, y)) [1]
quot(x, 0, s(z)) → s(div(x, s(z))) [1]
plus(x, 0) → x [1]
plus(0, y) → y [1]
div(0, y) → 0 [1]
div(x, y) → quot(x, y, y) [1]
times(s(0), y) → y [1]
quot(s(x), s(y), z) → quot(x, y, z) [1]
times(0, y) → 0 [1]
quot(0, s(y), z) → 0 [1]

Rewrite Strategy: INNERMOST

(5) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(6) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

plus(s(x), y) → s(plus(x, y)) [1]
times(s(x), y) → plus(y, times(x, y)) [1]
quot(x, 0, s(z)) → s(div(x, s(z))) [1]
plus(x, 0) → x [1]
plus(0, y) → y [1]
div(0, y) → 0 [1]
div(x, y) → quot(x, y, y) [1]
times(s(0), y) → y [1]
quot(s(x), s(y), z) → quot(x, y, z) [1]
times(0, y) → 0 [1]
quot(0, s(y), z) → 0 [1]

The TRS has the following type information:
plus :: s:0 → s:0 → s:0
s :: s:0 → s:0
times :: s:0 → s:0 → s:0
quot :: s:0 → s:0 → s:0 → s:0
0 :: s:0
div :: s:0 → s:0 → s:0

Rewrite Strategy: INNERMOST

(7) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

quot(v0, v1, v2) → null_quot [0]
plus(v0, v1) → null_plus [0]
times(v0, v1) → null_times [0]

And the following fresh constants:

null_quot, null_plus, null_times

(8) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

plus(s(x), y) → s(plus(x, y)) [1]
times(s(x), y) → plus(y, times(x, y)) [1]
quot(x, 0, s(z)) → s(div(x, s(z))) [1]
plus(x, 0) → x [1]
plus(0, y) → y [1]
div(0, y) → 0 [1]
div(x, y) → quot(x, y, y) [1]
times(s(0), y) → y [1]
quot(s(x), s(y), z) → quot(x, y, z) [1]
times(0, y) → 0 [1]
quot(0, s(y), z) → 0 [1]
quot(v0, v1, v2) → null_quot [0]
plus(v0, v1) → null_plus [0]
times(v0, v1) → null_times [0]

The TRS has the following type information:
plus :: s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times
s :: s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times
times :: s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times
quot :: s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times
0 :: s:0:null_quot:null_plus:null_times
div :: s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times → s:0:null_quot:null_plus:null_times
null_quot :: s:0:null_quot:null_plus:null_times
null_plus :: s:0:null_quot:null_plus:null_times
null_times :: s:0:null_quot:null_plus:null_times

Rewrite Strategy: INNERMOST

(9) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
null_quot => 0
null_plus => 0
null_times => 0

(10) Obligation:

Complexity RNTS consisting of the following rules:

div(z', z'') -{ 1 }→ quot(x, y, y) :|: z' = x, z'' = y, x >= 0, y >= 0
div(z', z'') -{ 1 }→ 0 :|: z'' = y, y >= 0, z' = 0
plus(z', z'') -{ 1 }→ x :|: z'' = 0, z' = x, x >= 0
plus(z', z'') -{ 1 }→ y :|: z'' = y, y >= 0, z' = 0
plus(z', z'') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z'' = v1, z' = v0
plus(z', z'') -{ 1 }→ 1 + plus(x, y) :|: z' = 1 + x, z'' = y, x >= 0, y >= 0
quot(z', z'', z1) -{ 1 }→ quot(x, y, z) :|: z' = 1 + x, z1 = z, z >= 0, x >= 0, y >= 0, z'' = 1 + y
quot(z', z'', z1) -{ 1 }→ 0 :|: z1 = z, z >= 0, y >= 0, z'' = 1 + y, z' = 0
quot(z', z'', z1) -{ 0 }→ 0 :|: v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, z' = v0
quot(z', z'', z1) -{ 1 }→ 1 + div(x, 1 + z) :|: z'' = 0, z >= 0, z' = x, x >= 0, z1 = 1 + z
times(z', z'') -{ 1 }→ y :|: z'' = y, y >= 0, z' = 1 + 0
times(z', z'') -{ 1 }→ plus(y, times(x, y)) :|: z' = 1 + x, z'' = y, x >= 0, y >= 0
times(z', z'') -{ 1 }→ 0 :|: z'' = y, y >= 0, z' = 0
times(z', z'') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z'' = v1, z' = v0

Only complete derivations are relevant for the runtime complexity.

(11) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V6),0,[plus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V6),0,[times(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V6),0,[quot(V, V1, V6, Out)],[V >= 0,V1 >= 0,V6 >= 0]).
eq(start(V, V1, V6),0,[div(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(plus(V, V1, Out),1,[plus(V2, V3, Ret1)],[Out = 1 + Ret1,V = 1 + V2,V1 = V3,V2 >= 0,V3 >= 0]).
eq(times(V, V1, Out),1,[times(V5, V4, Ret11),plus(V4, Ret11, Ret)],[Out = Ret,V = 1 + V5,V1 = V4,V5 >= 0,V4 >= 0]).
eq(quot(V, V1, V6, Out),1,[div(V7, 1 + V8, Ret12)],[Out = 1 + Ret12,V1 = 0,V8 >= 0,V = V7,V7 >= 0,V6 = 1 + V8]).
eq(plus(V, V1, Out),1,[],[Out = V9,V1 = 0,V = V9,V9 >= 0]).
eq(plus(V, V1, Out),1,[],[Out = V10,V1 = V10,V10 >= 0,V = 0]).
eq(div(V, V1, Out),1,[],[Out = 0,V1 = V11,V11 >= 0,V = 0]).
eq(div(V, V1, Out),1,[quot(V12, V13, V13, Ret2)],[Out = Ret2,V = V12,V1 = V13,V12 >= 0,V13 >= 0]).
eq(times(V, V1, Out),1,[],[Out = V14,V1 = V14,V14 >= 0,V = 1]).
eq(quot(V, V1, V6, Out),1,[quot(V15, V16, V17, Ret3)],[Out = Ret3,V = 1 + V15,V6 = V17,V17 >= 0,V15 >= 0,V16 >= 0,V1 = 1 + V16]).
eq(times(V, V1, Out),1,[],[Out = 0,V1 = V18,V18 >= 0,V = 0]).
eq(quot(V, V1, V6, Out),1,[],[Out = 0,V6 = V19,V19 >= 0,V20 >= 0,V1 = 1 + V20,V = 0]).
eq(quot(V, V1, V6, Out),0,[],[Out = 0,V21 >= 0,V6 = V22,V23 >= 0,V1 = V23,V22 >= 0,V = V21]).
eq(plus(V, V1, Out),0,[],[Out = 0,V24 >= 0,V25 >= 0,V1 = V25,V = V24]).
eq(times(V, V1, Out),0,[],[Out = 0,V26 >= 0,V27 >= 0,V1 = V27,V = V26]).
input_output_vars(plus(V,V1,Out),[V,V1],[Out]).
input_output_vars(times(V,V1,Out),[V,V1],[Out]).
input_output_vars(quot(V,V1,V6,Out),[V,V1,V6],[Out]).
input_output_vars(div(V,V1,Out),[V,V1],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [ (div)/3,quot/4]
1. recursive : [plus/3]
2. recursive [non_tail] : [times/3]
3. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into quot/4
1. SCC is partially evaluated into plus/3
2. SCC is partially evaluated into times/3
3. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations quot/4
* CE 10 is refined into CE [20]
* CE 11 is refined into CE [21]
* CE 8 is refined into CE [22]
* CE 9 is refined into CE [23]
* CE 7 is refined into CE [24]


### Cost equations --> "Loop" of quot/4
* CEs [23] --> Loop 13
* CEs [24] --> Loop 14
* CEs [20,21] --> Loop 15
* CEs [22] --> Loop 16

### Ranking functions of CR quot(V,V1,V6,Out)

#### Partial ranking functions of CR quot(V,V1,V6,Out)
* Partial RF of phase [13,14]:
- RF of loop [13:1]:
V
V1 depends on loops [14:1]
- RF of loop [14:1]:
-V1+1 depends on loops [13:1]


### Specialization of cost equations plus/3
* CE 15 is refined into CE [25]
* CE 13 is refined into CE [26]
* CE 14 is refined into CE [27]
* CE 12 is refined into CE [28]


### Cost equations --> "Loop" of plus/3
* CEs [28] --> Loop 17
* CEs [25] --> Loop 18
* CEs [26] --> Loop 19
* CEs [27] --> Loop 20

### Ranking functions of CR plus(V,V1,Out)
* RF of phase [17]: [V]

#### Partial ranking functions of CR plus(V,V1,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V


### Specialization of cost equations times/3
* CE 17 is refined into CE [29]
* CE 18 is refined into CE [30]
* CE 19 is refined into CE [31]
* CE 16 is refined into CE [32,33,34,35,36]


### Cost equations --> "Loop" of times/3
* CEs [36] --> Loop 21
* CEs [35] --> Loop 22
* CEs [33] --> Loop 23
* CEs [34] --> Loop 24
* CEs [32] --> Loop 25
* CEs [29] --> Loop 26
* CEs [30,31] --> Loop 27

### Ranking functions of CR times(V,V1,Out)
* RF of phase [21,22,23,24,25]: [V]

#### Partial ranking functions of CR times(V,V1,Out)
* Partial RF of phase [21,22,23,24,25]:
- RF of loop [21:1,22:1,23:1,24:1,25:1]:
V


### Specialization of cost equations start/3
* CE 2 is refined into CE [37,38]
* CE 3 is refined into CE [39]
* CE 4 is refined into CE [40,41,42,43,44]
* CE 5 is refined into CE [45,46]
* CE 6 is refined into CE [47,48]


### Cost equations --> "Loop" of start/3
* CEs [41] --> Loop 28
* CEs [37,38,39,40,42,43,44,45,46,47,48] --> Loop 29

### Ranking functions of CR start(V,V1,V6)

#### Partial ranking functions of CR start(V,V1,V6)


Computing Bounds
=====================================

#### Cost of chains of quot(V,V1,V6,Out):
* Chain [[13,14],16]: 1*it(13)+2*it(14)+2
Such that:it(13) =< V
aux(6) =< -V1
aux(5) =< -V1+1
it(14) =< it(13)+aux(6)
it(14) =< it(13)+aux(5)

with precondition: [V1>=0,V6>=0,Out>=1,V1+V6>=1,Out+V1>=2,V+1>=Out+V1]

* Chain [[13,14],15]: 1*it(13)+2*it(14)+1
Such that:it(13) =< V
aux(5) =< -V1+1
it(14) =< it(13)+aux(5)

with precondition: [V>=0,V1>=0,V6>=0,Out>=0,V+V6>=1,Out+V>=1,V1+V6>=1,Out+V1>=1]

* Chain [16]: 2
with precondition: [V=0,V1=0,Out=1,V6>=1]

* Chain [15]: 1
with precondition: [Out=0,V>=0,V1>=0,V6>=0]


#### Cost of chains of plus(V,V1,Out):
* Chain [[17],20]: 1*it(17)+1
Such that:it(17) =< -V1+Out

with precondition: [V+V1=Out,V>=1,V1>=0]

* Chain [[17],19]: 1*it(17)+1
Such that:it(17) =< Out

with precondition: [V1=0,V=Out,V>=1]

* Chain [[17],18]: 1*it(17)+0
Such that:it(17) =< Out

with precondition: [V1>=0,Out>=1,V>=Out]

* Chain [20]: 1
with precondition: [V=0,V1=Out,V1>=0]

* Chain [19]: 1
with precondition: [V1=0,V=Out,V>=0]

* Chain [18]: 0
with precondition: [Out=0,V>=0,V1>=0]


#### Cost of chains of times(V,V1,Out):
* Chain [[21,22,23,24,25],27]: 8*it(21)+1*s(15)+2*s(16)+1
Such that:aux(13) =< V1
aux(18) =< V
it(21) =< aux(18)
aux(14) =< aux(13)
s(15) =< it(21)*aux(13)
s(16) =< it(21)*aux(14)

with precondition: [V>=1,V1>=0,Out>=0]

* Chain [[21,22,23,24,25],26]: 8*it(21)+1*s(15)+2*s(16)+1
Such that:aux(13) =< V1
aux(19) =< V
it(21) =< aux(19)
aux(14) =< aux(13)
s(15) =< it(21)*aux(13)
s(16) =< it(21)*aux(14)

with precondition: [V>=2,V1>=0,Out>=0]

* Chain [27]: 1
with precondition: [Out=0,V>=0,V1>=0]

* Chain [26]: 1
with precondition: [V=1,V1=Out,V1>=0]


#### Cost of chains of start(V,V1,V6):
* Chain [29]: 22*s(33)+4*s(34)+4*s(35)+2*s(42)+4*s(43)+3
Such that:s(39) =< V1
aux(22) =< V
aux(23) =< -V1
aux(24) =< -V1+1
s(33) =< aux(22)
s(34) =< s(33)+aux(24)
s(35) =< s(33)+aux(23)
s(35) =< s(33)+aux(24)
s(41) =< s(39)
s(42) =< s(33)*s(39)
s(43) =< s(33)*s(41)

with precondition: [V>=0,V1>=0]

* Chain [28]: 1*s(50)+1
Such that:s(50) =< V

with precondition: [V1=0,V>=0]


Closed-form bounds of start(V,V1,V6):
-------------------------------------
* Chain [29] with precondition: [V>=0,V1>=0]
- Upper bound: 30*V+3+6*V1*V+nat(-V1+1)*4
- Complexity: n^2
* Chain [28] with precondition: [V1=0,V>=0]
- Upper bound: V+1
- Complexity: n

### Maximum cost of start(V,V1,V6): 29*V+2+6*V1*V+nat(-V1+1)*4+ (V+1)
Asymptotic class: n^2
* Total analysis performed in 369 ms.

(12) BOUNDS(1, n^2)